package org.finesys.common.es.pool;

import org.apache.commons.pool2.impl.GenericObjectPool;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;

import co.elastic.clients.elasticsearch.ElasticsearchAsyncClient;
import lombok.extern.slf4j.Slf4j;

/**
 * 异步池化管理
 */
@Slf4j
public class ElasticsearchAsyncClientPool extends GenericObjectPool<ElasticsearchAsyncClient> {

    // 连接工厂
    private final ElasticsearchAsyncClientFactory elasticsearchAsyncClientFactory;
    // 连接池配置
    private final GenericObjectPoolConfig<ElasticsearchAsyncClient> genericObjectPoolConfig;

    public ElasticsearchAsyncClientPool(ElasticsearchAsyncClientFactory elasticsearchAsyncClientFactory, GenericObjectPoolConfig<ElasticsearchAsyncClient> genericObjectPoolConfig) {
        // 初始化对象连接池
        super(elasticsearchAsyncClientFactory);
        // 初始化对象连接池
        this.elasticsearchAsyncClientFactory = elasticsearchAsyncClientFactory;
        this.genericObjectPoolConfig = genericObjectPoolConfig;
    }


    public ElasticsearchAsyncClientFactory getElasticsearchAsyncClientFactory() {
        return this.elasticsearchAsyncClientFactory;
    }


    public GenericObjectPoolConfig<ElasticsearchAsyncClient> getGenericObjectPoolConfig() {
        return this.genericObjectPoolConfig;
    }
}
